package api

import (
	"github.com/gin-gonic/gin"
	jwt "github.com/golangblogs/gojwt"
	"yk/api/handler"
	"yk/api/middleware"
	"yk/consts"
)

func Router(r *gin.Engine) {

	r.Use(middleware.Cqrs())

	api := r.Group("/api")
	{
		user := api.Group("/user")
		{
			user.POST("/register", handler.Register)
			user.POST("/login", handler.Login)
		}

		video := api.Group("/video")
		{
			video.GET("/listVideo", handler.ListVideo)
			video.POST("/detailVideo", handler.DetailVideo)
			video.POST("/updatedVideo", handler.UpdateVideo)
			video.POST("/delVideo", handler.DelVideo)
			video.POST("/upload", handler.Upload)
		}

		chat := api.Group("/chat")
		{
			chat.Use(jwt.JWTAuth(consts.JWT_SECRET_KEY))
			chat.GET("/ws", handler.Chat)
		}

		admin := api.Group("/admin")
		{
			admin.Use(jwt.JWTAuth(consts.JWT_SECRET_KEY))
			admin.POST("/addAdmin", handler.Admin)
		}

		subject := api.Group("/subject")
		{
			subject.GET("/listSubject", handler.ListSubject)
			subject.Use(jwt.JWTAuth(consts.JWT_SECRET_KEY))
			subject.POST("/addSubject", handler.AddSubject)
			subject.POST("/detailSubject", handler.DetailSubject)

		}

		barrage := api.Group("/barrage")
		{
			barrage.Use(jwt.JWTAuth(consts.JWT_SECRET_KEY))
			barrage.POST("/addBarrage", handler.AddBarrage)
			barrage.POST("/listBarrage", handler.ListBarrage)
		}

	}

}
